package UIFree.controls
{
	import SEApp.se_util;
	
	import UIFree.uif_component;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;

	public class uif_mainMenu extends uif_leavesBlock {
		private var _offset: Number;
		
		public function uif_mainMenu(parent:uif_component, menuList: Array, styleClass: String) {
			var rect: Rectangle = parent.getInner();
			super(parent, rect.x, rect.y, rect.width, 45, styleClass);
			_offset = 0;
			menuList.forEach(function(item: Object, index:int, arr: Array): void {
				addButton(item.caption, item.release);
			});
			
			align 		= uif_leavesBlock.TOPALIGN;
			addEvent(MouseEvent.ROLL_OVER, doOver);
			addEvent(MouseEvent.ROLL_OUT, doOut);
		}
		
		override protected function get minState(): Number {
			return 0.2;
		}
		
		private function doOver(e: MouseEvent): void {
			show();
		}
		
		private function doOut(e: MouseEvent): void {
			hide();
		}
		
		protected function addButton(caption: String, releaseObject: Object): void {
			var doRelease: Function;
			if (releaseObject is Function) doRelease = releaseObject as Function;
			else if (releaseObject is String) doRelease = function(e: Event): void {
				dispatchEvent(new Event(releaseObject as String));
			}
			var button: uif_gbutton = se_util.defButton(block, _offset, 0, caption, doRelease);
			_offset += button.width;
		}
		
		
	}
}